package com.shelpe.services.scheduler.item.order;

import org.springframework.batch.item.ItemProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import com.shelpe.services.scheduler.dto.OrderCustomerDto;
import com.shelpe.services.scheduler.po.SyncLog;
import com.shelpe.services.scheduler.syncclient.OrderCustomerClient;
import com.shelpe.services.scheduler.util.Util;


public class OrderCustomerProcessor implements ItemProcessor<Long, SyncLog>{

	@Autowired
	private OrderCustomerClient client;
	
	@Value("${simbaschedule.articleCode}")
	private String articleCode;
	
	@Override
	public SyncLog process(Long item) throws Exception {
		// TODO Auto-generated method stub
		
		OrderCustomerDto dto = new OrderCustomerDto();
		
		if(item != null && !item.equals(0)){
			
			client.deleteAllOrderCustomer();
			
			dto = client.syncOrderCustomer();
			
			client.syncOrderByArticleCode(articleCode);
		}
		
		SyncLog log = null;
		log = Util.convert(dto);
		
		return log;
	}

}
